package com.caiyi.financial.nirvana.sms.service;

import com.caiyi.financial.nirvana.sms.base.service.BaseService;
import com.caiyi.financial.nirvana.sms.entity.SmsGatewayTemplate;
import com.caiyi.financial.nirvana.sms.mapper.SmsGatewayTemplateMapper;
import com.caiyi.financial.nirvana.sms.querybean.GatewayTemplateQueryBean;
import com.caiyi.financial.nirvana.sms.querybean.PageBean;
import com.caiyi.financial.nirvana.sms.vo.SmsGatewayTemplateVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsGatewayTemplateService extends BaseService<SmsGatewayTemplate> {
    @Autowired
    private SmsGatewayTemplateMapper smsGatewayTemplateMapper;

    public int addGatewayTemplate(SmsGatewayTemplate smsGatewayTemplate) {
        int insertCount = this.insertByEntitySelective(smsGatewayTemplate);
        return insertCount;
    }

    public int deleteGatewayTemplate(Integer id) {
        SmsGatewayTemplate smsGatewayTemplate = new SmsGatewayTemplate();
        smsGatewayTemplate.setId(id);
        int deleteCount = this.deleteByPrimaryKey(smsGatewayTemplate);
        logger.info("deleteByGatewayTemplateId id {}", id);
        return deleteCount;
    }

    public int updateGatewayTemplate(SmsGatewayTemplate smsGatewayTemplate) {
        int updateCount = this.updateByEntitySelective(smsGatewayTemplate);
        return updateCount;
    }

    public PageBean<SmsGatewayTemplateVo> getGatewayTemplateByParams(GatewayTemplateQueryBean bean) {
        PageHelper.startPage(bean.getPageNum(), bean.getPageSize());
        List<SmsGatewayTemplateVo> list = smsGatewayTemplateMapper.selectGatewayTemplateListByParams(bean);
        PageBean<SmsGatewayTemplateVo> pageBean = new PageBean<>(list);
        return pageBean;
    }
}
